<?php

/**
 * 关于我们表
 */
class about_us_info extends CActiveRecord
{
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'about_us_info';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		return array(
			array('type_name_cn,type_name_en,title_name_cn,title_name_en,body_name_cn,body_name_en,time', 'safe'),
		);
	}

	/**
	 *通过id返回查询到的数量
	 * @param $id
	 *
	 * @return bool
     */
    function countForId($id){
		if(!$id>0){ return false;}
		$sql="SELECT COUNT(`id`) as `cnt` FROM `".$this->tableName()."` Where `id`=:id ";
		$cnt=about_us_info::model()->countBySql($sql,array(':id'=>$id));
		return $cnt;
	}

	/**
	 * 返回类型数据
	 * @param string $lang
	 *
	 * @return mixed
     */
    function getTypeData($lang=''){
		if($lang=='en'){
			$sql="SELECT *,`type_name_en` as `type_name` FROM `".$this->tableName()."` GROUP BY `type_name_en` ORDER BY `id` ASC";
		}else{
			$sql="SELECT *,`type_name_cn` as `type_name` FROM `".$this->tableName()."` GROUP BY `type_name_cn` ORDER BY `id` ASC ";
		}
		$data=about_us_info::getDbConnection()->createCommand($sql)->queryAll();
		return $data;
	}

	/**
	 * 通过id返回相应数据
	 * @param        $id
	 * @param string $lang
	 *
	 * @return mixed
     */
    function getData($id,$lang=''){
		if($id>0){$where=" and `id`='$id'";}
		if($lang=='en'){
			$sql="SELECT *,`title_name_en` as `title_name`,`body_name_en` as `body_name` FROM `".$this->tableName()."` WHERE 1=1 $where  LIMIT 1";
		}else{
			$sql="SELECT *,`title_name_cn` as `title_name`,`body_name_cn` as `body_name` FROM `".$this->tableName()."` WHERE 1=1 $where  LIMIT 1 ";
		}
		$data=about_us_info::getDbConnection()->createCommand($sql)->queryAll();
		return $data;
	}



}
